package lt.liepasoft.locr.data;

public class Bounds {
 
    public final int 
            x1,y1,x2,y2,width,height;

    public Bounds(int x1, int y1, int x2, int y2) {                        
        if (x1<0) x1=0;
        if (x2<0) x2=0;
        if (y1<0) y1=0;
        if (x2<0) x2=0;
        
        if ((x2-x1) > 0){
            this.x1=x1;
            this.x2=x2;
            width = x2-x1;
        } else {
            this.x1 = x2;
            this.x2 = x1;
            width = x1-x2;
        }
        
        if ((y2-y1) > 0){
            this.y1=y1;
            this.y2=y2;
            height = y2-y1;
        } else {
            this.y1 = y2;
            this.y2 = y1;
            height = y1-y2;
        }                
    }

    @Override
    public String toString() {
        return "x1:"+x1+" y1:"+y1+" x2:"+x2+" y2:"+y2+" w:"+width+" h:"+height;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Bounds){            
            Bounds b = (Bounds)obj;
            return (x1==b.x1&&y1==b.y1&&x2==b.x2&&y2==b.y2);
        } else
            return super.equals(obj);
    }

    /**
     * Returns a hash code value for the object.\n 
     * This method is supported for the benefit of hash \n
     * tables such as those provided by HashMap.
     * @return 
     */
    @Override    
    public int hashCode() {
        int hash = 7;
        hash = 53 * hash + this.x1;
        hash = 53 * hash + this.y1;
        hash = 53 * hash + this.x2;
        hash = 53 * hash + this.y2;
        return hash;
    }
    
}
